package com.titan.demo.camel.sample.eip.使用choice实现分支;

import java.util.HashMap;
import java.util.Map;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.LoggingLevel;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;

import com.titan.demo.camel.utils.RunCamel;

public class Test02 {
	public static void main(String[] args) {
        try {
        	RouteBuilder route = createRouteBuilder();
        	createRunCamel().run(route);
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	
	private static RunCamel createRunCamel() {
		return new RunCamel() {
			protected void execute(CamelContext context,
					ProducerTemplate producer, ConsumerTemplate consumer)
					throws Exception {
				Map<String,Object> data = new HashMap<String,Object>();
				data.put("k1", "v11");
				data.put("k2", "v22");				
				
				producer.sendBody("direct:in", data);
			}
		};
	}
	
	private static RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("direct:in")
            	.choice()
            	.when().simple("${body[k1]} == 'v11'")
                   	.log(LoggingLevel.INFO, this.getClass().getName(), "Processing: 1111")
        		.otherwise()
                   	.log(LoggingLevel.INFO, this.getClass().getName(), "Processing: 2222")
                ;
            }
        };
    }
}
